﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LoginIn.DesignerCS
{
    public partial class UserControl2 : UserControl
    {
        int a, sum;
        private void c_fun(String ID)
        {

            String whereStmt = "";
             whereStmt += "Stu_ID='" + ID + "'";
            
            String oldSelectStmt = oleDbDataAdapter1.SelectCommand.CommandText;

            // 将查询条件附加到原查询命令的后面
            String selectStmt = oleDbDataAdapter1.SelectCommand.CommandText;
            if (whereStmt.Length > 0) selectStmt += " WHERE " + whereStmt;

            // 更改oleDbAdapter1的查询命令
            oleDbDataAdapter1.SelectCommand.CommandText = selectStmt;

            // 执行新的查询并填充数据集
            dataSet91.Clear();
            oleDbDataAdapter1.Fill(dataSet91);
            //开始计算分数
             a = dataSet91.Tables[0].Rows.Count;
             sum = 0;
            Console.WriteLine(a);
            for (int i = 0; i < a; i++)
            {
            sum +=(int)dataSet91.Cour_Info.Rows[i]["Points"];
            }
            Console.WriteLine(sum);
            // 恢复oleDbAdapter1的查询命令
            oleDbDataAdapter1.SelectCommand.CommandText = oldSelectStmt;

        }

        public UserControl2(String ID)
        {
            InitializeComponent();
            c_fun(ID);
            contofcla.Text = a+" " ;
            contofpoint.Text = sum+" ";


        }

        private void UserControl2_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (a < 3)
            {
                MessageBox.Show("选课数目少于三门，请重新选课!");
            }
            else if(a>5)
            {
                MessageBox.Show("选课数目多于五门，请重新选课!");
            }
            else if (sum<8)
            {
                MessageBox.Show("已选课程学分少于八分，请重新选课!");
            }
            else if (sum> 12)
            {
                MessageBox.Show("已选课程学分多于十二分，请重新选课!");
            }
            else 
            {
                MessageBox.Show("选课信息提交成功！");
            }
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }
}
